<?php
/**
 * 新闻资讯
 * User: jh
 * Date: 2018-03-20
 * Time: 16:29
 */

namespace frontend\controllers;


use common\models\Exhibition;
use common\models\News;
use common\models\NewsCategory;
use common\services\ExhibitionServices;
use common\services\NewsServices;
use frontend\base\BaseFrontController;
use Yii;

class NewsController extends BaseFrontController
{
    public function actionIndex()
    {
        $params = Yii::$app->request->queryParams;
        $news = new NewsServices();
        $params['category_id'] = isset($params['categoryId']) ? (int)$params['categoryId'] : "";
        $params['defaultPageSize'] = 8;
        $news = $news->newsList($params);
        $categoryName = '';
        if (!empty($params['category_id'])) {
            $categoryName = NewsCategory::getNewsCategoryName($params['category_id']);
        }

        return $this->render('list',[
            'news' => $news['news'],
            'pages' => $news['pagination'],
            'categoryName' => $categoryName,
        ]);
    }

    /**
     * 资讯详情
     * @param $id
     * @return string
     */
    public function actionDetail($id)
    {
        $news = new NewsServices();
        $news = $news->detail($id);

        return $this->render('detail',[
            'news'=>$news
        ]);
    }
}